package org.spruice;

import java.util.ArrayList;
import java.util.List;

class BinderLifecycle implements org.springframework.context.Lifecycle {

    private boolean running;
    private List<Runnable> onStart = new ArrayList<Runnable>();
    private List<Runnable> onStop = new ArrayList<Runnable>();
    private List<Runnable> destroyable;

    public void setOnStart(List<Runnable> onStart) {
        this.onStart = onStart;
    }

    public void setOnStop(List<Runnable> onStop) {
        this.onStop = onStop;
    }

    public void start() {
        for (Runnable runnable : onStart) {
            runnable.run();
        }
        running = true;
    }

    public void stop() {
        for (Runnable runnable : onStop) {
            runnable.run();
        }
        running = false;
    }

    public void destroy() {
        for (Runnable runnable : destroyable) {
            runnable.run();
        }
    }

    public boolean isRunning() {
        return running;
    }

    public void setOnDestroy(List<Runnable> destroyable) {
        this.destroyable = destroyable;
    }
}
